package com.wmeimob.fastboot.jiubei.controller;

import com.github.pagehelper.PageInfo;
import com.wmeimob.fastboot.core.context.PageContext;
import com.wmeimob.fastboot.jiubei.entity.Member;
import com.wmeimob.fastboot.jiubei.service.MemberService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author wjt
 * @version 1.0
 * @className MemberController
 * @description 【会员表】控制器
 * @date Mon Aug 24 21:15:22 CST 2020
 **/
@RestController
@RequestMapping("member")
@Slf4j
public class MemberController {

    @Resource
    private MemberService memberService;


    /**
     * 会员表分页查询
     *
     * @param member
     * @return
     */
    @GetMapping
    public PageInfo queryForMember(Member member) {
        PageContext.startPage();
        return new PageInfo<Member>(memberService.list(member));

    }

    /**
     * 会员表导出
     *
     * @param member
     * @return
     */
    @PostMapping("/export")
    public List<Member> queryForMemberExport(@RequestBody Member member) {
        return memberService.list(member);
    }


    /**
     * 会员表查询-<通过id查询>
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Member queryForMemberById(@PathVariable("id") Object id) {
        return memberService.queryMemberById(id);
    }


    /**
     * 会员表添加
     *
     * @param member
     * @return
     */
    @PostMapping
    public void insertForMember(@RequestBody Member member) {
        memberService.addMember(member);
    }


    /**
     * 会员表修改
     *
     * @param member
     * @return
     */
    @PutMapping
    public void updateForMember(@RequestBody Member member) {
        memberService.modifyMember(member);
    }

    /**
     * 会员表删除
     *
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public void removeForMember(@PathVariable("id") Long id) {
        memberService.removeMember(id);
    }
}
